﻿using Shop.DAL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;

namespace Shop.BLL
{
    public class BaseManager<T> where T : class,new()
    {
        protected BaseService<T> service=new BaseService<T>();
        public virtual bool Add(T entity)
        {
            try
            {
                return service.Add(entity) > 0;
            }
            catch
            {
                throw;
            }
        }

        public virtual bool Update(T entity)
        {
            try
            {
                return service.Update(entity) > 0;
            }
            catch
            {
                throw;
            }
        }

        public virtual bool Delete(int id)
        {
            try
            {
                return service.Delete(id)>0;
            }
            catch
            {
                throw;
            }
        }

        public virtual T GetEntity(int id)
        {
            try
            {
                return service.GetEntity(id);
            }
            catch
            {
                throw;
            }
        }

        public virtual List<T> GetList(string where="", SqlParameter[] sp=null)
        {
            try
            {
                return service.GetList(where, sp);
            }
            catch
            {
                throw;
            }
        }

        public virtual List<T> GetList(string where, SqlParameter[] sp, int pageindex, int pageSize, out int total)
        {
            try
            {
                return service.GetList(where, sp, pageindex, pageSize, out total);
            }
            catch
            {
                throw;
            }
        }
    }
}
